package jp.joogoo.web.controller;

import jp.joogoo.web.service.AuthorizeService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class DashboardController extends Controller {

    private AuthorizeService auth = new AuthorizeService();

    @Override
    protected Navigation run() throws Exception {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
 
        if (user != null) {
            if (auth.isAuthorized(user)) {
                requestScope("userId", user.getUserId());
                requestScope("logoutUrl", userService.createLogoutURL("/"));
                return forward("dashboard.jsp");
            } else {
                return redirect("/addservice");
            }
        } else {
            return redirect("/");
        }
    }
}
